<template>
	<view class="booking">
		<navBar @onSearchConfirm="getProgramDelegationInfoData" @onChangePrint="getProgramDelegationInfoData" />
		<!-- 返回 -->
		<Nav :title="title" :filtertitle="title+'查询'" :data="filterData" :form.sync="filterForm" :inpdata="inputData" @finsh='onFinshData' />
		<!-- <view class="titles">在线预约</view> -->
		<!-- <text>当前滚动高度：{{ scrollTop }}px</text> -->
		<!-- 我的意向单 -->
		<scroll-view class="mybook" scroll-y="true">
			<view class="bkitem" @click="getOrderDetail(item.orderNum,item.folderNo)" v-for="(item,index) in List"
				:key="index">
				<view class="bkrol bkdjs">
					<text class="colorb">订单编号：<text class="sheetc">{{ item.orderNum }}</text></text>
					<text class="status bgf">{{ item.nationalLotteryNum ? '国抽' : '企抽' }}</text>
				</view>
				<view class="bkrol" v-if="item.folderNo">
					LIMS订单编号：<text class="names">{{ item.folderNo }}</text>
				</view>
				<view class="bkrol" v-if="item.contractCode">
					合同单号：<text class="names">{{ item.contractCode }}</text>
				</view>
				<view class="bkrol" v-if="item.nationalLotteryNum">
					国抽单号：<text class="names">{{ item.nationalLotteryNum }}</text>
				</view>
				<view class="bkrol bkdjs">
					<text class="colors">业务类型：<text class="status">{{ item.businessType }}</text></text>
					<text class="colors">销售员：<text class="colorb">{{ item.salesmanName }}</text></text>
				</view>
				<view class="bkrol bkdjs">
					<text class="colors">检验类别：<text class="colorb">{{ item.inspectionCategory }}</text></text>
					<text class="colors">细分领域：<text class="colorb">{{ item.subBusiness }}</text></text>
				</view>
				<view class="bkrol txr">
					<text>创建时间：{{ item.createdTime }}</text>
				</view>
			</view>
			<view class="toolbar-height"></view>
		</scroll-view>
	</view>
</template>

<script>
	// 引入api
	import {
		getProgramDelegationInfo, // 委托单查询
		getProgramQuotationInfo // 报价单查询
	} from "@/proxy/program/program.api.js";
	export default {
		async onLoad(option) {
			if (option.method === "weituo") {
				await this.getProgramDelegationInfoData(option.projectName); // 获取委托单
				// 只有委托单才有状态选择
				this.filterData = [
					{
						children: false, //是否有子项
						title: "委托单状态",
						key: "delegationStatus", //键名 接收对象名字
						keyValue: "value", //获取的值是哪个
						isRadio: true, //是否单选 否则多选
						data: [
							{
								title: "草稿",
								id: 1,
								value: 'Draft',
							},
							{
								title: "已记录",
								id: 2,
								value: 'Logged',
							},
							{
								title: "完成",
								id: 3,
								value: 'Done',
							},
							{
								title: "OOS",
								id: 4,
								value: 'OOS',
							},
							{
								title: "已取消",
								id: 5,
								value: 'Cancelled',
							},
							{
								title: "活动",
								id: 6,
								value: 'Active',
							},
							{
								title: "预记录",
								id: 7,
								value: 'Prelogged',
							}
						],
					}
				];
			} else if (option.method === "baojia") {
				await this.getProgramQuotationInfoData(); // 获取报价单
			}
			// this.title = option.title;
			this.method = option.method;
			// console.log("获取到的参数", option)
		},
		data() {
			return {
				title: "加载中...", // 标题
				method: "", // 请求方式
				List: [], // 单列表
				filterForm: {},
				inputData: [
					{
						title: "LIMS订单编号",
						placeholder:"请输入LIMS订单编号",
						inpValue:"",
						key: "folderNo", //键名 接收对象名字
					},
					{
						title: "报价单号",
						placeholder:"请输入报价单号",
						inpValue:"",
						key: "quotationNun", //键名 接收对象名字
					},
					{
						title: "订单编号",
						placeholder:"请输入订单编号",
						inpValue:"",
						key: "orderNum", //键名 接收对象名字
					},
					{
						title: "检测项目名称",
						placeholder:"请输入检测项目名称",
						inpValue:"",
						key: "projectName", //键名 接收对象名字
					},
				],
				filterData: []
			}
		},
		methods: {
			// 筛选后的值
			async onFinshData(data) {
				// console.log('父组件接收子组件返回的筛选值', data)
				if (this.method === "weituo") {
					await this.getProgramDelegationInfoData(data.projectName,data.quotationNun,data.orderNum,data.folderNo,data.delegationStatus); // 获取委托单
				} else if (this.method === "baojia") {
					await this.getProgramQuotationInfoData(data.projectName,data.quotationNun,data.orderNum,data.folderNo,data.delegationStatus); // 获取报价单
				}
			},
			// 委托单查询
			async getProgramDelegationInfoData(projectName,quotationNun,orderNum,folderNo,delegationStatus) {
				const {
					customerCode,
					businessName
				} = uni.getStorageSync("userInfo");
				if (!customerCode) {
					return this.$toast({
						title: "请前往小程序授权登录",
						// icon: "error",
					});
				}
				// 发送请求
				try {
					const result = await getProgramDelegationInfo([{
						customerCode: customerCode,
						businessType: businessName,
						projectName: projectName,
						quotationNun: quotationNun,
						orderNum: orderNum,
						folderNo: folderNo,
						delegationStatus: delegationStatus,
					}]);
					if (result.code == 200) {
						this.title = "委托单";
						this.List = result.data;
						// console.log("委托单查询成功！！！", result);
					} else {
						return this.$toast({
							title: result.data.msg,
						});
					}
				} catch (error) {
					console.error("请求失败", error);
					return this.$toast({
						title: "请求失败",
						icon: "error",
					});
				}
			},
			// 报价单查询
			async getProgramQuotationInfoData(projectName,quotationNun,orderNum,folderNo,delegationStatus) {
				const {
					customerCode,
					businessName
				} = uni.getStorageSync("userInfo");
				if (!customerCode) {
					return this.$toast({
						title: "请前往小程序授权登录",
						// icon: "error",
					});
				}
				// 发送请求
				try {
					const result = await getProgramQuotationInfo([{
						customerCode: customerCode,
						businessType: businessName,
						projectName: projectName,
						quotationNun: quotationNun,
						orderNum: orderNum,
						folderNo: folderNo,
						delegationStatus: delegationStatus,
					}]);
					if (result.code == 200) {
						this.title = "报价单";
						this.List = result.data;
						// console.log("报价单查询成功！！！", result);
					} else {
						return this.$toast({
							title: result.data.msg,
						});
					}
				} catch (error) {
					console.error("请求失败", error);
					return this.$toast({
						title: "请求失败",
						icon: "error",
					});
				}
			},
			getOrderDetail(orderNum, folderNo) {
				let pages = `/pagesClient/detection/orderdetail?orderNum=${orderNum}&folderNo=${folderNo}&method=${this.method}`;
				this.$goto(pages);
			}
		}
	}
</script>

<style lang="scss">
	// page {
	// 	background-color: rgb(249, 250, 251);
	// 	// height: 100vh;
	// }
	/* app端 */
	/* #ifdef APP-PLUS || H5 */
	#app,
	/* #endif */
	page {
	  background-color: #F9FAFB;
	  height: 100%;
	}
	.colors {
		color: #6C7381;
	}

	.colorb {
		color: #000;
	}

	.names {
		font-size: 28rpx;
		font-weight: bold;
	}

	.status {
		color: #FFF;
		background: #FF0000;
		padding: 5rpx 10rpx;
		border-radius: 10rpx;
	}

	.bgf {
		background: #0081ff;
	}

	.txr {
		text-align: right;
		letter-spacing: 2rpx;
	}

	.booking {
		height: 100vh;
		display: flex;
		flex-direction: column;

		// background-color: rgb(249,250,251);
		.mybook {
			// margin: 20rpx;
			flex: 1;
			overflow-y: auto;
			width: auto;

			.bkitem {
				// padding: 20rpx 20rpx 0;
				padding: 0rpx 10rpx 10rpx 10rpx;
				font-size: 25rpx;
				margin: 20rpx;
				background-color: #fff;
				box-shadow: #bbb 0 0 8rpx;
				border-radius: 15rpx;

				// box-shadow: 0 0 30rpx rgba(0, 0, 0, 0.1);
				// border-bottom: 1rpx solid #f4f4f4;
				.bkdjs {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.controls {
						color: #0081ff;

						.rolsl {
							margin-right: 10rpx;
						}
					}
				}

				.bkrol {
					padding: 10rpx 0;

					// height: 60rpx;
					// line-height: 60rpx;
					.sheetc {
						font-size: 30rpx;
						font-weight: bold;
					}
				}

				// .remark{
				// 	margin: 10rpx 0rpx;
				// }
			}
		}
	}

	// 底部占位空盒子
	.toolbar-height {
		height: 20rpx;
	}
</style>